<?php

/*
raing 0.3.1
release date: 28 February 2013
description: raing is a simple template script to manage request
             parsing and routing in PHP language. It is very
             simple so that you can costumize it easily until it
             is not even raing anymore. Have fun with it!
author: toyo - http://dimas.muskay.org/
how to use: ask toyo, read this source code file
*/

// import all what needed
require('application/db.php');
require('application/helper.php');
include('application/WideImage/WideImage.php');
include('application/PHPMailer/class.phpmailer.php');
//controller
require('controller/404.php');
require('controller/home.php');
require('controller/about.php');
require('controller/studio.php');
require('controller/bimbel.php');
require('controller/sanggar.php');
require('controller/yayasan.php');
require('controller/produk.php');
require('controller/contact.php');
require('controller/backend.php');
require('controller/email.php');
//view
require('view/backend.php');
require('view/_init.php');
require('view/home.php');
require('view/about.php');
require('view/studio.php');
require('view/bimbel.php');
require('view/sanggar.php');
require('view/yayasan.php');
require('view/produk.php');
require('view/contact.php');

class raing {
    private $config;
    
    public function __construct() {
        // http://php.net/manual/en/timezones.php
        date_default_timezone_set('Asia/Jakarta');
        
        // set config
        $this->config = array();
        $this->config['ruri'] = array();
        $this->config['root_path'] = dirname(__FILE__).DIRECTORY_SEPARATOR;
        $this->config['image_path'] = dirname(__FILE__).DIRECTORY_SEPARATOR.'asset'.DIRECTORY_SEPARATOR.'img'.DIRECTORY_SEPARATOR;
        $this->config['home_url'] = 'http://'.$_SERVER['SERVER_NAME'].substr($_SERVER['SCRIPT_NAME'],0,strpos($_SERVER['SCRIPT_NAME'],'index.php'));
        $this->config['image_url'] = $this->config['home_url'].'asset/img/';
        $this->config['style_url'] = $this->config['home_url'].'asset/style/';
        $this->config['script_url'] = $this->config['home_url'].'asset/script/';
        $this->config['db_host'] = 'localhost';
        $this->config['db_user'] = 'root';
        $this->config['db_pass'] = 'bismillah';
        $this->config['db_name'] = 'balerupa';
        $this->config['prefix'] = '';
		
		//curang
		define('image_url', $this->config['image_url']);
    }
    
    public function start() {
		ob_start();
		session_start();
        // getting route param
        $path_info = isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : (isset($_SERVER['ORIG_PATH_INFO']) ? $_SERVER['ORIG_PATH_INFO'] : false);
        if ($path_info) {
            $this->config['ruri'] = explode('/',$path_info);
            array_shift($this->config['ruri']);
            if (end($this->config['ruri']) =='') {
                array_pop($this->config['ruri']);
            }
            reset($this->config['ruri']);
        }

        // give to controller
        if (empty($this->config['ruri'])) {
            controller_home($this->config);
        } elseif ($this->config['ruri'][0] == 'about') {
            controller_about($this->config);
        } elseif ($this->config['ruri'][0] == 'cstudio') {
            controller_studio($this->config);
        } elseif ($this->config['ruri'][0] == 'bimbel') {
            controller_bimbel($this->config);
        } elseif ($this->config['ruri'][0] == 'sanggar') {
            controller_sanggar($this->config);
        } elseif ($this->config['ruri'][0] == 'yayasan') {
            controller_yayasan($this->config);
        } elseif ($this->config['ruri'][0] == 'produk') {
            controller_produk($this->config);
        } elseif ($this->config['ruri'][0] == 'contact') {
            controller_contact($this->config);
        } elseif ($this->config['ruri'][0] == 'email') {
            controller_email($this->config);
        } elseif ($this->config['ruri'][0] == 'backend') {
            controller_backend($this->config);
        } else {
            controller_404($this->config);
        }
    }
}

// start the machine
$machine = new raing();
$machine->start();

/*
Copyright (C) 2013  toyo

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/
